var express = require('express');
var router = express.Router();
var CONFIG = require('../../../../common/config');
var CODE = require('../../../../common/code');
var superagent = require('superagent');
var cheerio = require('cheerio');      //  爬虫相关
var retUtil = require('../util/retUtil');
var userUtil = require('../util/userUtil');
var api4backUtil = require('./util/api4backUtil');
var staticizeUtil = require('../util/staticizeUtil');
var api4backRouterUtil = require('./routerUtil/api4backRouterUtil');

var YjxTradeOrderModel = require('../../../../common/yjxMysql/mapping/YjxTradeOrderModel');
var CommonUtil = require('../../../../common/util/CommonUtil');
var SJGNode = require('./../../../sjg/common/tg/SJGNode');
var SJGTG = require('./../../../sjg/common/tg/SJGTG');
var SJGTGV3 = require('./../../../sjg/common/tg3/SJGTGV3');
var SJGNodeV3 = require('./../../../sjg/common/tg3/SJGNodeV3');
var activityService = require('../../../service/activityService');

/**
 * 初始化一键秀 app 搜索缓存
 *
 * @author 王俊
 * @date 2017-11-24
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/initSearchCache
 * */
function initSearchCache(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var force = retUtil.numberFromReq(req, 'force');
    api4backUtil.buildSearchRedisCache(force, function (error, data) {
        if(error) {
            console.log('yjx/v1/api4bacck/api4bacck/initSearch err: ' + error);
            // 如果不是约定的特殊错误, 则走正常错误逻辑
            if(error !== '重复建立') {
                return retUtil.ret_err_json(error, res);
            }
            var obj = {
                buildStart : data.buildStart,
                buildEnd : data.buildEnd
            };
            return retUtil.ret_func_json(0, data.errMsg, obj, res);
        }
        var obj = {
            buildStart : data.buildStart
        };
        return retUtil.ret_func_json(1, '缓存后台建立中, 预计时间: 10 min', obj, res);
    });
}
router.get('/initSearchCache', initSearchCache);
router.post('/initSearchCache', initSearchCache);

/**
 * 切换搜索 redis db
 *
 * @author 王俊
 * @date 2017-11-25
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/switchSearchDB
 * */
function switchSearchDB(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    api4backUtil.switchSearchDB(function (error, data) {
        if(error) {
            console.log('yjx/v1/api4bacck/api4bacck/switchSearchDB err: ' + error);
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/switchSearchDB', switchSearchDB);
router.post('/switchSearchDB', switchSearchDB);


/**
 * 清空搜索 redis 的离线缓存
 *
 * @author 王俊
 * @date 2017-11-28
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/clearSearchDB
 * */

function clearSearchDB(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    api4backUtil.clearSearchDB(function (error, data) {
         if(error) {
             return retUtil.ret_err_json(error, res);
         }
         return retUtil.ret_succ_json(data, res);
    });
}
router.get('/clearSearchDB', clearSearchDB);
router.post('/clearSearchDB', clearSearchDB);


/**
 * 强制建立搜索的 redis 缓存
 *
 * @author 王俊
 * @date 2017-11-29
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/forceBuildSearchRedisCache
 */
function forceBuildSearchRedisCache(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    api4backUtil.forceBuildSearchRedisCache(function (error, data) {
        if(error) {
            // 如果不是约定的特殊错误, 则走正常错误逻辑
            if(error !== '重复建立') {
                return retUtil.ret_err_json(error, res);
            }
            var errMsg = data.errMsg;
            data.errMsg = undefined;
            return retUtil.ret_func_json(0, errMsg, data, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/forceBuildSearchRedisCache', forceBuildSearchRedisCache);
router.post('/forceBuildSearchRedisCache', forceBuildSearchRedisCache);


/**
 * 查询搜索的 redis 缓存建立状态
 *
 * @author 王俊
 * @date 2017-11-29
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/querySearchRedisStatus
 */
function querySearchRedisStatus(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    api4backUtil.querySearchRedisStatus(function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/querySearchRedisStatus', querySearchRedisStatus);
router.post('/querySearchRedisStatus', querySearchRedisStatus);

/**
 * 查询接口的缓存 keys 列表
 *
 * @author 王俊
 * @date 2017-11-29
 *
 * 参数[可选]: prefix, 指定获取接口的前缀
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/getStaticizeUtilKeys?prefix=/yjx/v1/document/getTmplDefaultContour
 */

function getStaticizeUtilKeys(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var prefix = retUtil.stringFromReq(req, 'prefix') || '*';
    if(prefix && prefix.length > 1 && prefix.indexOf('*') === -1) {
        prefix += '*';
    }
    staticizeUtil.getAllPatternCacheKeys(prefix, function (error, keys) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        var retData = {
            keys : keys
        };
        return retUtil.ret_succ_json(retData, res);
    });
}
router.get('/getStaticizeUtilKeys', getStaticizeUtilKeys);
router.post('/getStaticizeUtilKeys', getStaticizeUtilKeys);

/**
 * 删除指定接口的缓存
 *
 * @author 王俊
 * @date 2017-11-29
 *
 * 参数[可选]: prefix 要删除的 key 的前缀, 若不传递则标记删除所有 key
 *
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/delStaticizeUtilCache?prefix=/yjx/v1/document/getTmplDefaultContour_v1_0
 */
function delStaticizeUtilCache(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var prefix = retUtil.stringFromReq(req, 'prefix') || '*';
    if(prefix.indexOf('*') === -1) {
        prefix += '*';
    }
    // 如果要删除全部缓存
    if(prefix === '*') {
        staticizeUtil.clearDataByRedis(function (error) {
            if(error) {
                return retUtil.ret_err_json(error, res);
            }
            return retUtil.ret_succ_json({}, res);
        });
        return;
    }
    // 如果要删除指定缓存
    staticizeUtil.delRedisStaticDataByPattern(prefix, function (error) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json({}, res);
    });
}
router.get('/delStaticizeUtilCache', delStaticizeUtilCache);
router.post('/delStaticizeUtilCache', delStaticizeUtilCache);

// 获取一键秀用户订单作品信息
function getOrderUserDocInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    // get parameter
    var strOrderIds = req.body.orderIds || req.query.orderIds || null;// json数组
    if(!strOrderIds || strOrderIds.length==0){
        return retUtil.ret_err_json(null, res);
    }

    var orderIds = JSON.parse(strOrderIds||'[]');
    if(!orderIds || orderIds.length==0){
        return retUtil.ret_err_json(null, res);
    }

    // 从一条纪录中提取数据
    function getTextsInfo(item){
        // 解析提纲树
        var ver = item.ver;
        var data = item.data
        data = CommonUtil.process_before_JSON_Parse(data);

        var tree = null;
        if(ver<SJGNode.VERSION_3){
            tree =new SJGTG();
            tree.fromJson(JSON.parse(data),ver);
        }else{
            tree =new SJGTGV3();
            tree.fromJson(JSON.parse(data),ver);
        }

        // 从提纲树中提取文字[提取root的子对象
        var texts = [];
        var titles = [];
        for(var i=0; i<tree.root.children.length; i++){
            var node = tree.root.children[i];
            if(node.kind==SJGNode.SJGNODE_KIND_3  && node.type==SJGNode.SJGNODE_TYPE_1){
                var t = node.value.value;
                var topic = node.topic;
                texts.push(t);
                titles.push(topic);
            }
        }

        return [texts, titles];
    }

    // 获取订单文档
    (new YjxTradeOrderModel).getOrderUserDocInfo(null, orderIds, function(error, items) {
        if (error || !items || items.length==0) {
            console.log(error);
            return retUtil.ret_err_json(error, res);
        }

        // 提取items中的data中的文字
        var list = [];
        for(var i=0;i<items.length;i++){
            var one = items[i];
            if(one && one.data){
                var r = getTextsInfo(one);
                if(r){
                    list.push({
                        orderId: one.order_id||null,
                        orderDetailId: one.detail_id||null,
                        userDocId: one.doc_id||null,
                        designType: one.design_type||0,
                        designId: one.design_id||null,
                        titles: r[1],
                        texts: r[0]
                    });
                }
            }
        }

        var data={
            list:list
        };
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getOrderUserDocInfo', getOrderUserDocInfo);
router.post('/getOrderUserDocInfo', getOrderUserDocInfo);


//################################################################################
/**
 * 获取组织用户信息列表
 * @author xc
 * @date  2018-07-09
 * @param pageNum   页码
 * @param pageSize  页容量
 * @param withTotalPage  是否需要总页数
 * @param orgId     组织id (必须)
 * @param mobile    用户手机号 (可选)
 * @param userId    用户id (可选)
 * @param nickname  用户昵称 (可选)
 */
function getYjxOrgUserInfoList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var pageNum = retUtil.numberFromReq(req,"pageNum") || 0;
    var pageSize = retUtil.numberFromReq(req,"pageSize");
    var withTotalPage = retUtil.numberFromReq(req,"withTotalPage") || 0;

    var userId = retUtil.numberFromReq(req,"userId") || 0;
    var mobile = retUtil.stringFromReq(req, 'mobile') || '';
    var nickname = retUtil.stringFromReq(req, 'nickname') || '';

    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    if(!orgId || orgId <= 0) {
        return retUtil.ret_err_json("参数有误",res)
    }

    //存储基本的参数信息
    var param = {
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage,
        orgId : orgId,
        userId : userId,
        mobile : mobile,
        nickname : nickname
    };
    api4backUtil.getYjxOrgUserInfoList(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getYjxOrgUserInfoList', getYjxOrgUserInfoList);
router.post('/getYjxOrgUserInfoList', getYjxOrgUserInfoList);

/**
 * 添加一键秀[合作公司]成员
 * @author xc
 * @date  2018-06-11
 * @param mobile 成员手机号
 * @param verCd  手机验证码
 * @param orgId  组织id
 * @param desc   备注
 */
function addYjxCoopUserInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var mobile = retUtil.stringFromReq(req, 'mobile') || '';
    var verCd = retUtil.stringFromReq(req, 'verCd') || '';
    var desc = retUtil.stringFromReq(req, 'desc') || '';
    var orgId = retUtil.numberFromReq(req, 'orgId') || 0;

    if(mobile.length==0 || verCd.length<6) {
        return retUtil.ret_err_json('手机号或验证码无效', res);
    }

    if(orgId == 0) {
        return retUtil.ret_err_json('无效公司组织', res);
    }

    // 验证手机号是否合法正则
    var reg = /^1\d{10}$/;
    //验证手机号的合法性
    if(!(reg.test(mobile))){
        return retUtil.ret_err_json("手机号无效", res);
    }
    // 检查验证码
    userUtil.validByVerCode("86", mobile, verCd,function (chkErr) {
        if (chkErr) {
            return retUtil.ret_err_json(chkErr, res);
        }

        api4backUtil.addYjxCoopUserInfo(mobile, orgId, desc, function(addErr, addRet){
            if(addErr) {
                return retUtil.ret_err_json(addErr, res);
            }
            return retUtil.ret_succ_json(addRet, res);
        });
    });
}
router.get('/addYjxCoopUserInfo', addYjxCoopUserInfo);
router.post('/addYjxCoopUserInfo', addYjxCoopUserInfo);

/**
 * 移除合作方成员(解除组织关联,不删除用户)
 * @author xc
 * @date  2018-06-25
 * @param userId 用户id
 * @param orgId  组织id
 */
function removeYjxCoopUser(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var orgId = retUtil.numberFromReq(req, 'orgId') || 0;

    if(userId==0 || orgId==0) {
        return retUtil.ret_err_json('参数错误', res);
    }

    var param = {
        orgId: orgId,
        userId: userId,
        delFlg: 1
    };
    api4backUtil.updYjxOrgRInfo(param, function(updErr, updRet){
        if(updErr) {
            return retUtil.ret_err_json(updErr, res);
        }
        return retUtil.ret_succ_json(updRet, res);
    });
}
router.get('/removeYjxCoopUser', removeYjxCoopUser);
router.post('/removeYjxCoopUser', removeYjxCoopUser);

/**
 * 更新YJX组织关联信息
 * @author xc
 * @date  2018-06-25
 * @param userId 用户id
 * @param orgId  组织id
 * @param desc   备注
 */
function updYjxOrgRDesc(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var desc = retUtil.stringFromReq(req, 'desc') || '';
    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var orgId = retUtil.numberFromReq(req, 'orgId') || 0;

    if(userId==0 || orgId==0) {
        return retUtil.ret_err_json('参数错误', res);
    }

    var param = {
        orgId: orgId,
        userId: userId,
        desc: desc
    };
    api4backUtil.updYjxOrgRInfo(param, function(updErr, updRet){
        if(updErr) {
            return retUtil.ret_err_json(updErr, res);
        }
        return retUtil.ret_succ_json(updRet, res);
    });
}
router.get('/updYjxOrgRDesc', updYjxOrgRDesc);
router.post('/updYjxOrgRDesc', updYjxOrgRDesc);

/**
 * 获取合作方参与活动列表
 * @author xc
 * @date 2018-06-25
 *
 * 参数：pageNum  页码
 * 参数：pageSize  页容量
 * 参数：withTotalPage  是否需要总页数
 * 参数：coopOrgId  合作组织id (必须)
 * 参数：findStates  活动状态数组: [30,40]
 * 参数：withRewardInfo  是否返回奖励信息
 * 参数：title  活动标题
 */
function getCoopActInfoList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var pageNum = retUtil.numberFromReq(req,"pageNum") || 0;
    var pageSize = retUtil.numberFromReq(req,"pageSize");
    var withTotalPage = retUtil.numberFromReq(req,"withTotalPage") || 0;

    var withRewardInfo = retUtil.numberFromReq(req,"withRewardInfo") || 0;
    var title = retUtil.stringFromReq(req, 'title') || '';
    var strFindStates = retUtil.stringFromReq(req, 'findStates') || '[]';
    var findStates = JSON.parse(strFindStates);

    var coopOrgId = retUtil.numberFromReq(req,"coopOrgId") || 0;
    if(!coopOrgId || coopOrgId <= 0) {
        return retUtil.ret_err_json("参数有误",res)
    }

    //存储基本的参数信息
    var param = {
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage,
        findStates : findStates||[],
        coopOrgId : coopOrgId,
        withRewardInfo : withRewardInfo,
        title : title
    };
    api4backUtil.getCoopActInfoList(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getCoopActInfoList', getCoopActInfoList);
router.post('/getCoopActInfoList', getCoopActInfoList);

/**
 * 获取组织参与活动的统计信息
 * @author xc
 * @date 2018-07-11
 * 参数:orgId  用户所属组织id
 * 返回值: {
 *    "success":1,
 *    "msg":"成功",
 *    "data":{
 *        "reward":184000,
 *        "actCnt":3,
 *        "prodCnt":7,
 *        "userCnt":4
 *    }
 *  }
 */
function getOrgActStatsInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    if(!orgId || orgId <= 0) {
        return retUtil.ret_err_json("参数错误",res)
    }

    var param = {
        orgId : orgId,
    };
    api4backUtil.getOrgActStatsInfo(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getOrgActStatsInfo', getOrgActStatsInfo);
router.post('/getOrgActStatsInfo', getOrgActStatsInfo);

/**
 * 获取参与活动的用户作品列表
 * @author xc
 * @date 2018-06-26
 *
 * 参数：pageNum  页码
 * 参数：pageSize  页容量
 * 参数：withTotalPage  是否需要总页数
 * 参数：orgId  用户所属组织id
 * 参数：actId  活动id
 * 参数：userId  用户id
 * 参数：mobile  用户手机号
 * 参数：findStates  作品状态数组: [10新建, 20评审中, 30通过, 40不通过]
 */
function getActUserProdInfoList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var pageNum = retUtil.numberFromReq(req,"pageNum") || 0;
    var pageSize = retUtil.numberFromReq(req,"pageSize");
    var withTotalPage = retUtil.numberFromReq(req,"withTotalPage") || 0;

    var mobile = retUtil.stringFromReq(req, 'mobile') || '';
    var strFindStates = retUtil.stringFromReq(req, 'findStates') || '[]';
    var findStates = JSON.parse(strFindStates);

    var userId = retUtil.numberFromReq(req,"userId") || 0;
    var actId = retUtil.numberFromReq(req,"actId") || 0;
    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    if(!orgId || orgId <= 0) {
        //return retUtil.ret_err_json("参数有误",res)
    }

    //存储基本的参数信息
    var param = {
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage,
        findStates : findStates||[],
        orgId : orgId,
        actId : actId,
        userId : userId,
        mobile : mobile
    };
    api4backUtil.getActUserProdInfoList(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getActUserProdInfoList', getActUserProdInfoList);
router.post('/getActUserProdInfoList', getActUserProdInfoList);
//################################################################################


/**
 * 获取抖音链接的信息
 *
 * @author 李强
 * @date 2018-06-08
 *
 * 参数: url 抖音分享地址
 *
 * 测试地址: http://yapi.yijianxiu.com:7000/mock/34/yjx/v1/api4back/spiderDouyinShare
 */
function spiderDouyinShare(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var url = retUtil.stringFromReq(req, 'url') || '';

    if(!url || url.length<=0 && url.indexOf('http') !== 0){
        return retUtil.ret_err_json("参数错误", res);
    }
    api4backUtil.spiderDouyinUrl(url, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/spiderDouyinShare', spiderDouyinShare);
router.post('/spiderDouyinShare', spiderDouyinShare);

/*
* 获取企业活动详情
*
* @author 王俊
* @date 2018-06-11
*
* 参数: userId           用户 id
* 参数: orgId            组织 id
* 参数: activityId       活动 id
*
* 文档地址: http://yapi.yijianxiu.com:7000/project/34/interface/api/3476
* */
function getOrgActivityDetail(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var userId = retUtil.numberFromReq(req, 'userId');
    var orgId = retUtil.numberFromReq(req, 'orgId');
    var activityId = retUtil.numberFromReq(req, 'activityId');

    if(userId <=0 || orgId <=0 || activityId <=0) {
        return retUtil.ret_err_json('参数错误', res);
    }

    var opt = {
        userId : userId,
        orgId : orgId,
        activityId : activityId
    };
    api4backUtil.getOrgActivityDetail(opt, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }

        //######## 活动参与人数过少, 暂时以作品数冒充参与人数 ###############
        data.brief.totalUsers = Math.ceil(data.brief.totalProducts*0.9);
        //######## 活动参与人数过少, 暂时以作品数冒充参与人数 ###############
        return retUtil.ret_succ_json(data, res);
    });

}
router.get('/getOrgActivityDetail', getOrgActivityDetail);
router.post('/getOrgActivityDetail', getOrgActivityDetail);


/*
* 查看企业活动作品排行
*
* @author 王俊
* @date 2018-06-11
*
* 参数: userId           用户 id
* 参数: orgId            组织 id
* 参数: activityId       活动 id
* 参数: pageNum          页码
* 参数: pageSize         页容量
*
* 文档地址: http://yapi.yijianxiu.com:7000/project/34/interface/api/3484
* */
function getOrgActivityProducts(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var userId = retUtil.numberFromReq(req, 'userId');
    var orgId = retUtil.numberFromReq(req, 'orgId');
    var activityId = retUtil.numberFromReq(req, 'activityId');
    var pageNum = retUtil.numberFromReq(req, 'pageNum') || 0;
    var pageSize = retUtil.numberFromReq(req, 'pageSize');
    var withTotalPage = retUtil.numberFromReq(req, 'withTotalPage');

    if(userId <=0 || orgId <=0 || activityId <=0 || pageSize <=0) {
        return retUtil.ret_err_json('参数错误', res);
    }

    var opt = {
        userId : userId,
        orgId : orgId,
        activityId : activityId,
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage
    };
    api4backUtil.getOrgActivityProducts(opt, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getOrgActivityProducts', getOrgActivityProducts);
router.post('/getOrgActivityProducts', getOrgActivityProducts);



/**
 * 企业管理员登录
 *
 * @author 毛凯
 * @date 2018-6-11
 *
 * 参数: userName 企业登录名
 * 参数: password md5 密码
 * 测试地址: http://localhost:3000/yjx/v1/api4back/orgLogin?userName=xx&password=xxx
 */

function orgLogin(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var userName = retUtil.stringFromReq(req, 'userName');
    var password = retUtil.stringFromReq(req, 'password');
    if(!userName || !password || userName.length <= 0 || password.length <= 0) {
        return retUtil.ret_err_json("用户名或密码错误",res)
    }
    api4backUtil.orgLogin(userName, password,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/orgLogin', orgLogin);
router.post('/orgLogin', orgLogin);




/**
 * 获取企业发布活动列表
 *
 * @author 毛凯
 * @date 2018-6-11
 *
 * 参数: pageNum 页码
 * 参数: pageSize 页容量
 * 参数：userId   用户唯一标识
 * 参数：withTotalPage  是否需要总页数
 * 参数：orgId  组织id
 * 测试地址: http://localhost:3000/yjx/v1/api4back/getOrgActivityList?pageNum=xx&pageSize=xxx&userId=XX&withTotalPage=0&orgId=XX
 */
function getOrgActivityList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var pageNum = retUtil.numberFromReq(req,"pageNum") || 0;
    var pageSize = retUtil.numberFromReq(req,"pageSize");
    var userId = retUtil.numberFromReq(req,"userId");
    var withTotalPage = retUtil.numberFromReq(req,"withTotalPage") || 0;
    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    if(!userId || !orgId || userId <= 0 || orgId <= 0) {
        return retUtil.ret_err_json("参数有误",res)
    }
    //存储基本的参数信息
    var param = {
        states : [],
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage,
        orgId : orgId,
        userId : userId || 0,
        flag : 0
    };
    api4backUtil.getOrgActivityList(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getOrgActivityList', getOrgActivityList);
router.post('/getOrgActivityList', getOrgActivityList);







/**
 * (网红)公司计算某个活动的收益
 *
 * @author jackLiu
 * @date 2018-6-12
 *
 * 参数：orgId  组织id
 * 参数：activityId  活动id
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/calcPatnerActivityReward?orgId=1&activityId=5
 */
function calcPatnerActivityReward(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    var activityId = retUtil.numberFromReq(req,"activityId") || 0;
    if(!orgId ||  orgId <= 0 || !activityId || activityId <= 0) {
        return retUtil.ret_err_json("参数有误",res)
    }


    api4backUtil.calcPatnerActivityReward(orgId,activityId,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json({"reward":data}, res);
    });
}
router.get('/calcPatnerActivityReward', calcPatnerActivityReward);
router.post('/calcPatnerActivityReward', calcPatnerActivityReward);


/**
 * (网红)公司对某个活动的收益进行记账
 *
 * @author jackLiu
 * @date 2018-6-12
 *
 * 参数：orgId  组织id
 * 参数：activityId  活动id
 * 参数：reward  活动中该组织的总收益额，单位：分
 * 参数：tax  所缴纳的税款，单位：分[目前传0即可]
 * 测试地址: http://localhost:3000/yjx/v1/api4back/api4back/recordPartnerActivityCash?orgId=1&activityId=5&reward=50000&tax=0
 */
function recordPartnerActivityCash(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var orgId = retUtil.numberFromReq(req,"orgId") || 0;
    var activityId = retUtil.numberFromReq(req,"activityId") || 0;
    var reward = retUtil.numberFromReq(req,"reward")|| 0;
    var tax = retUtil.numberFromReq(req,"tax")|| 0;
    if(!orgId ||  orgId <= 0 || !activityId || activityId <= 0) {
        return retUtil.ret_err_json("参数有误",res)
    }


    api4backUtil.recordPartnerActivityCash(orgId,activityId,reward,tax,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/recordPartnerActivityCash', recordPartnerActivityCash);
router.post('/recordPartnerActivityCash', recordPartnerActivityCash);



/*
* 获取活动作品排名列表
*
* @author 王俊
* @date 2018-06-12
*
* 参数: activityId
*
* 接口地址: http://yapi.yijianxiu.com:7000/project/34/interface/api/3548
*
* */
function rankActProductScore(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var activityId = retUtil.numberFromReq(req, 'activityId');
    var pageNum = retUtil.numberFromReq(req, 'pageNum') || 0;
    var pageSize = retUtil.numberFromReq(req, 'pageSize');
    var withTotalPage = retUtil.numberFromReq(req, 'withTotalPage');

    var opt = {
        activityId : activityId,
        pageNum : pageNum,
        pageSize : pageSize,
        withTotalPage : withTotalPage
    };
    api4backUtil.rankActProductScore(opt, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });


}
router.get('/rankActProductScore', rankActProductScore);
router.post('/rankActProductScore', rankActProductScore);



/*
* 更新某活动中作品的点赞、评论等信息
*
* @author 王俊
* @date 2018-06-12
*
* 参数: activityId    活动 id
* 参数: productIds    指定的作品 id 数组的 json 字符串, 若不传递则默认更新该活动下所有作品
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3540
* */
function updateDouyinDataOfActivityProduct(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var activityId = retUtil.numberFromReq(req, 'activityId');
    var productIds = retUtil.arrayFromReq(req, 'productIds');
    var opt = {
        activityId : activityId,
        productIds : productIds
    };
    api4backUtil.updateDouyinDataOfActivityProduct(opt, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });

}
router.get('/updateDouyinDataOfActivityProduct', updateDouyinDataOfActivityProduct);
router.post('/updateDouyinDataOfActivityProduct', updateDouyinDataOfActivityProduct);



/*
* 计算并刷新活动作品排名,分值, 奖励 等信息
*
* @author 王俊
* @date 2018-06-13
*
* 参数: activityId 活动 id
* 接口地址: http://yapi.yijianxiu.com:7000/project/34/interface/api/3556
* */
function rankAndRefreshActProductsInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var activityId = retUtil.numberFromReq(req, 'activityId');
    api4backUtil.rankAndRefreshActProductsInfo(activityId, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/rankAndRefreshActProductsInfo', rankAndRefreshActProductsInfo);
router.post('/rankAndRefreshActProductsInfo', rankAndRefreshActProductsInfo);


/*
* 发放收益
*
* @author 毛凯
* @date 2018-06-13
*
* 参数: activityId    活动 id
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3540
* */
function issuingReceipts(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var activityId = retUtil.numberFromReq(req, 'activityId');
    if (!activityId || activityId <= 0){
        return retUtil.ret_err_json("参数错误", res);
    }
    api4backUtil.issuingReceipts(activityId, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json({}, res);
    });

}
router.get('/issuingReceipts', issuingReceipts);
router.post('/issuingReceipts', issuingReceipts);



/*
* 获取组织活动统计信息
*
* @author 毛凯
* @date 2018-06-15
*
* 参数: orgId    组织 id
* 参数：userId   用户id
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3604
* */
function getOrgActivityInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var orgId = retUtil.numberFromReq(req, 'orgId');
    var userId = retUtil.numberFromReq(req, 'userId');
    if (!orgId || orgId <= 0 || !userId || userId <= 0){
        return retUtil.ret_err_json("参数错误", res);
    }
    api4backUtil.getOrgActivityInfo(orgId,userId, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }

        //######### 活动参与人数过少, 以作品数冒充参与人数 ###############
        data.activity.totalJoinUser = Math.ceil(data.activity.totalProducts*0.9);
        //######### 活动参与人数过少, 以作品数冒充参与人数 ###############

        return retUtil.ret_succ_json(data, res);
    });

}
router.get('/getOrgActivityInfo', getOrgActivityInfo);
router.post('/getOrgActivityInfo', getOrgActivityInfo);




/*
* 更新活动实际访问次数
*
* @author 毛凯
* @date 2018-06-26
*
* 参数: actIds   [1,2,3,4,5]  活动 ids
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3708
* */
function refreshActViewCnt(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var actIds = retUtil.arrayFromReq(req, 'actIds') || [];
    api4backUtil.refreshActViewCnt(actIds, function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });

}
router.get('/refreshActViewCnt', refreshActViewCnt);
router.post('/refreshActViewCnt', refreshActViewCnt);



/*
* 生成优惠码/推广码
*
* @author 毛凯
* @date 2018-07-03
*
* 参数：cType    码类型：10直接抵扣,20满减券,30折扣券,40活动推广码
* 参数：userId   用户id（cType=40时必须）
* 参数: desc      我的推广码
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3772
* */
function createPromoCode(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var cType = retUtil.numberFromReq(req, 'cType');
    var userId = retUtil.numberFromReq(req, 'userId');
    var desc = retUtil.stringFromReq(req, 'desc');
    if(!cType || cType <= 0){
        return retUtil.ret_err_json("参数有误", res);
    }
    if (cType === 40 && userId && userId>0){
        api4backUtil.createPromoCode(cType,userId,desc,function (error, data) {
            if(error) {
                return retUtil.ret_err_json(error, res);
            }
            return retUtil.ret_succ_json(data, res);
        });
    }else{
        return retUtil.ret_err_json("该接口只支持生成推荐码", res);
    }
}
router.get('/createPromoCode', createPromoCode);
router.post('/createPromoCode', createPromoCode);


/*
* 修改推广码信息
*
* @author 毛凯
* @date 2018-07-03
*
* 参数：cId    码的数据库id  (cId和cCode至少有一个不为空)
* 参数：cCode   推广码 (cId和cCode至少有一个不为空)
* 参数: desc  码备注信息
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3780
* */
function updPromoCode(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var cId = retUtil.numberFromReq(req, 'cId');
    var cCode = retUtil.stringFromReq(req, 'cCode');
    var desc = retUtil.stringFromReq(req, 'desc');
    if(!cId || !cCode || !desc || cId<= 0){
        return retUtil.ret_err_json("参数有误", res);
    }
    api4backUtil.updPromoCode(cId,cCode,desc,function (error) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json({}, res);
    });
}
router.get('/updPromoCode', updPromoCode);
router.post('/updPromoCode', updPromoCode);


/*
* 获取推广码列表
*
* @author 毛凯
* @date 2018-07-03
*
* 参数：pageNum   请求页码
* 参数：pageSize   请求页容量
* 参数: withTotalPage  是否需要总页数
* 参数: cType    检索条件：码类型（10直接抵扣,20满减券,30折扣券,40活动推广码）
* 参数：userId   检索条件：用户id（只返回绑定到该用户的码）
* 参数： desc   检索条件：码备注（模糊匹配）
* 参数： state  检索条件：码状态
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3788
* */
function getPromoCodeList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var pageNum = retUtil.numberFromReq(req, 'pageNum');
    var pageSize = retUtil.numberFromReq(req, 'pageSize');
    var withTotalPage = retUtil.numberFromReq(req, 'withTotalPage') || 0;
    var cType = retUtil.arrayFromReq(req, 'cType')||[];
    var userId = retUtil.numberFromReq(req, 'userId');
    var desc = retUtil.stringFromReq(req, 'desc');
    var state = retUtil.arrayFromReq(req, 'state')||[];
    if(!pageSize || pageNum< 0){
        return retUtil.ret_err_json("参数有误", res);
    }
    api4backUtil.getPromoCodeList(pageNum,pageSize,withTotalPage,cType,userId,desc,state,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getPromoCodeList', getPromoCodeList);
router.post('/getPromoCodeList', getPromoCodeList);


/*
* 获取推广码奖励信息列表
*
* @author 毛凯
* @date 2018-07-03
*
* 参数：pageNum   请求页码
* 参数：pageSize   请求页容量
* 参数: withTotalPage  是否需要总页数
* 参数：actId    活动id
* 参数: cId    码id
* 参数：userId   检索条件：用户id（只返回绑定到该用户的码）
* 参数： desc   检索条件：码备注（模糊匹配）
* 参数：cCode 检索条件：码
*
* 接口文档: http://114.55.172.253:7000/project/34/interface/api/3788
* */
function getPromoCodeRewardList(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var pageNum = retUtil.numberFromReq(req, 'pageNum');
    var pageSize = retUtil.numberFromReq(req, 'pageSize');
    var withTotalPage = retUtil.numberFromReq(req, 'withTotalPage') || 0;
    var actId = retUtil.numberFromReq(req, 'actId');
    var cId = retUtil.numberFromReq(req, 'cId');
    var userId = retUtil.numberFromReq(req, 'userId');
    var desc = retUtil.stringFromReq(req, 'desc');
    var cCode = retUtil.stringFromReq(req, 'cCode');
    if(!pageSize || pageNum< 0){
        return retUtil.ret_err_json("参数有误", res);
    }
    api4backUtil.getPromoCodeRewardList(pageNum,pageSize,withTotalPage,actId,cId,userId,desc,cCode,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/getPromoCodeRewardList', getPromoCodeRewardList);
router.post('/getPromoCodeRewardList', getPromoCodeRewardList);


/***
 * 发送验证码
 * @author 毛凯
 * @date 2018-7-3
 * 方式: GET
 * 参数: mobile: 手机号
 * 参数: zone: 手机号对应区号(默认 +86)
 * 参数: type: 验证码类型, 暂定如下:1 短信验证码2 语音验证码暂时固定为1
 * 返回: {}
 *测试地址 : http://localhost:3000/yjx/v1/api4back/api4back/getBackMobileVerCode?device=610&mobile=18202755833&zone=+86&type=1
 */
function getBackMobileVerCode(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");//设置跨域访问:
    var mobile = retUtil.numberFromReq(req, 'mobile');
    var zone = retUtil.numberFromReq(req, 'zone') || 86;
    var type = retUtil.numberFromReq(req, 'type') || 1;
    if (mobile <= 0 || !((/^1\d{10}$/).test(mobile))) {
        return retUtil.ret_err_json("请输入正确的手机号", res);
    }
    if (type == 1) {
        api4backUtil.getBackMobileVerCode(zone,mobile, function (err,data) {
            if(err){
                return retUtil.ret_err_json(err, res);
            }
            return retUtil.ret_succ_json({}, res);
        })
    }else{
        return retUtil.ret_err_json("暂不支持其它获取验证码的方式", res);
    }
}
router.post('/getBackMobileVerCode', getBackMobileVerCode);
router.get('/getBackMobileVerCode', getBackMobileVerCode);


/**
 *
 * 手机号+验证码登录
 *
 * @author 毛凯
 * @date 2018-7-3
 *
 *
 * zone	   是  +86 国际区号, 暂时固定传 +86
 * mobile  是 18888888888  用户手机号, 验证规则同获取验证码
 * verCode 是 878789 六位验证码
 * 测试地址：http://localhost:3000/yjx/v1/api4back/api4back/checkBackMobileCode_v1_0?device=610&zone=+86&mobile=13469974378&verCode=123456
 */
function loginByBackMobileCode(req,res,next){
    var zone = retUtil.numberFromReq(req,'zone');
    var mobile = retUtil.stringFromReq(req,'mobile');
    var verCode = retUtil.stringFromReq(req,'verCode');
    if(!mobile || !verCode || verCode.length !== 6 || !zone  || zone <= 0  ){
        console.log("loginByMobileCode_v1_0 .... verCode.length="+verCode.length+"zone="+zone+"zone.length="+zone.length);
        return retUtil.ret_err_json("验证码有误",res);
    }
    //验证手机号是否合法正则
    var reg = /^1\d{10}$/;
    //验证手机号的合法性
    if(!(reg.test(mobile))){
        return retUtil.ret_err_json("手机号有误",res);
    }
    api4backUtil.loginByBackMobileCode(zone, mobile, verCode,function (getErr, userId) {
        if (getErr) {
            console.log('yjx/v1/usesr.js [loginByMobileCode_v1_0] loginByMobileCode_v1_0 getErr'+getErr);
            return retUtil.ret_err_json(getErr, res);
        }
        api4backUtil.getUserDetailInfo_v1_0(userId,function(err,data){
            if(err){
                console.log('yjx/v1/usesr.js [loginByMobileCode_v1_0 getUserDetailInfo_v1_0 ] loginByMobileCode_v1_0 getErr'+err);
                retUtil.ret_err_json(userId,res);
            }
            retUtil.ret_succ_json(data,res);
        })
    });
}

router.get('/loginByBackMobileCode', loginByBackMobileCode);
router.post('/loginByBackMobileCode', loginByBackMobileCode);

/**
 * 获取网红信息列表
 * @author 李琦
 * @date  2018-07-20
 * @param userId 用户id
 * @param orgId  组织id
 */
function getRedWedUserInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var orgId = retUtil.numberFromReq(req, 'orgId') || 0;

    if(userId==0 || orgId==0) {
        return retUtil.ret_err_json('参数错误', res);
    }

    var param = {
        orgId: orgId,
        userId: userId
    };
    api4backUtil.getRedWedUserInfo(param, function(err, ret){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(ret, res);
    });
}
router.get('/getRedWedUserInfo', getRedWedUserInfo);
router.post('/getRedWedUserInfo', getRedWedUserInfo);

/**
 * 给网红用户添加平台信息
 * @author 李琦
 * @date  2018-07-20
 */
function addUserPlat(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var currentUserId = retUtil.numberFromReq(req, 'currentUserId') || 0;
    var plat = retUtil.numberFromReq(req,'plat')||0;// 平台
    var platId = retUtil.stringFromReq(req,'platId')||0;// 平台私有ID 例如:抖音ID
    var fansNum = retUtil.stringFromReq(req,'fansNum')||0;// 粉丝数
    var likeNum = retUtil.stringFromReq(req,'likeNum')||0;// 点赞数

    if(!userId || !plat || !platId ||!fansNum){
        return retUtil.ret_err_json("参数为空",res);
    }

    var param = {
        userId:userId,
        currentUserId:currentUserId,
        plat:plat,
        platId:platId,
        fansNum:fansNum,
        likeNum:likeNum
    };
    api4backUtil.addUserPlat(param, function(err, ret){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(ret, res);
    });
}
router.get('/addUserPlat', addUserPlat);
router.post('/addUserPlat', addUserPlat);

/**
 * 删除网红平台资料
 * @author 李琦
 * @date  2018-07-20
 */
function delWebRedUserPlat(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var currentUserId = retUtil.numberFromReq(req, 'currentUserId') || 0;
    var info_id = retUtil.numberFromReq(req, 'info_id') || 0;

    if(!userId || !info_id){
        return retUtil.ret_err_json("参数为空",res);
    }

    var param = {
        userId:userId,
        currentUserId:currentUserId,
        info_id:info_id,
        del_flg:1,
    };
    api4backUtil.delUserPlat(param, function(err, ret){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(ret, res);
    });
}
router.get('/delWebRedUserPlat', delWebRedUserPlat);
router.post('/delWebRedUserPlat', delWebRedUserPlat);




/**
 * 初始化点赞活动配置等信息
 * @author 毛凯
 * @date  2018-07-20
 * 参数： actId  活动id
 *
 */
function initActivityInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问
    var actId = retUtil.numberFromReq(req, 'actId') || 0;
    if(!actId || actId<=0){
        return retUtil.ret_err_json("参数错误", res);
    }
    api4backRouterUtil.initActivityInfo(actId,function(err, data){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/initActivityInfo', initActivityInfo);
router.post('/initActivityInfo', initActivityInfo);

/*
* 刷新活动状态
*
* @author 王俊
* @date 2018-08-02
*
* */
function refreshActivityState(req, res, next) {
    const opt = {
        type: 20,   // 刷新图片点赞活动
    };
    activityService.refreshActivityState(opt, function (error, data) {
        if(error) return retUtil.ret_err_json(error, res);
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/refreshActivityState', refreshActivityState);
router.post('/refreshActivityState', refreshActivityState);

/**
 * 获取单个平台资料
 * @author 李琦
 */
function getPlatInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;
    var currentUserId = retUtil.numberFromReq(req, 'currentUserId') || 0;
    var cInfoId = retUtil.numberFromReq(req, 'cInfoId') || 0;

    if(!userId || !cInfoId){
        return retUtil.ret_err_json("参数为空",res);
    }

    var param = {
        userId:userId,
        currentUserId:currentUserId,
        c_info_id:cInfoId,
    };

    api4backUtil.getPlatInfo(param, function(err, ret){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(ret, res);
    });
}
router.get('/getPlatInfo', getPlatInfo);
router.post('/getPlatInfo', getPlatInfo);



/**
 * 编辑网红资料
 * @author 李琦
 */
function editWebRedUserInfo(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var userId = retUtil.numberFromReq(req, 'userId') || 0;// 用户
    var orgId = retUtil.numberFromReq(req, 'orgId') || 0;// 组织ID
    var currentUserId = retUtil.numberFromReq(req, 'currentUserId') || 0;// 当前用户
    var desc = retUtil.stringFromReq(req, 'desc') || 0;// 用户备注
    var labs = retUtil.stringFromReq(req, 'labs') || 0;// 标签信息
    var sex = retUtil.numberFromReq(req, 'sex') || 0;// 用户性别
    var phone = retUtil.numberFromReq(req, 'phone') || 0;// 用户电话

    var birth_year = retUtil.numberFromReq(req, 'birth_year') || 0;// 年份
    var birth_month = retUtil.numberFromReq(req, 'birth_month') || 0;// 月份
    var birth_day = retUtil.numberFromReq(req, 'birth_day') || 0;// 日子
    var prov = retUtil.numberFromReq(req, 'prov') || 0;// 省
    var city = retUtil.numberFromReq(req, 'city') || 0;// 城市
    var dist = retUtil.numberFromReq(req, 'dist') || 0;// 区


    if(!userId || !orgId ||!birth_year){
        return retUtil.ret_err_json("参数为空",res);
    }

    var param = {
        userId:userId,
        orgId:orgId,
        currentUserId:currentUserId,
        desc:desc,
        gender:sex,
        birth_year:birth_year,
        birth_month:birth_month,
        birth_day:birth_day,
        prov:prov,
        city:city,
        dist:dist,
        labs:labs,
        phone:phone,
    };
    api4backUtil.editWebRedUser(param, function(err, ret){
        if(err) {
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(ret, res);
    });
}
router.get('/editWebRedUserInfo', editWebRedUserInfo);
router.post('/editWebRedUserInfo', editWebRedUserInfo);

module.exports = router;